package search;

import java.util.Arrays;
import java.util.List;

/**
 * @description: 顺序查找
 * @title: SequentialSearch
 * @author: zp
 * @date: 2021/11/25 20:47
 */
public class SequentialSearch {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
        System.out.println(search(list, 2));
    }

    public static int search(List<Integer> list, int findValue) {
        for (int i = 0; i < list.size(); i++) {
            if (findValue == list.get(i)) {
                return i;
            }
        }
        return -1;
    }
}
